<template>
	<div class="addresslist">
		<van-address-list
		  v-model="chosenAddressId"
		  :list="list"
		  default-tag-text="默认"
		  @add="onAdd"
		  @edit="onEdit"
		/>
	</div>
</template>


<script>
import {getAddressList} from "../api/index.js"

export default {
  name: 'AddressList',
  data(){
	  return{
		 chosenAddressId:"1",
		 list:[
			 // {
			 //    id: '1',
			 //    name: '张三',
			 //    tel: '13000000000',
			 //    address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
			 //    isDefault: true,
			 // }
		 ] 
	  }
  },
  created(){
	  this.getData();
  },
  methods:{
	  getData(){
		  getAddressList().then((data)=>{
			  if(+data.resultCode==200&&data.data.length>0){
				  this.list=data.data.map((item)=>{
					  return{
						  id: item.addressId,
						  name:item.userName,
						  tel: item.userPhone,
						  address:item.provinceName +
								  item.cityName +
								  item.regionName +
								  item.detailAddress,
						  isDefault: item.defaultFlag,
					  }
				  });
				  //console.log(this.list);
			  }
		  })
	  },
	  onAdd(){
		  this.$router.push("/addressedit");
	  },
	  onEdit(item, index){
		  //console.log(item, index);
		  this.$router.push("/addressedit?addressId=" + item.id);
	  }
  },
  watch:{
	  chosenAddressId(val){
		 // console.log(val);
		 //跳转到生成订单页
		  this.$router.push("/createOrder?addressId="+val);
	  }
  }
}
</script>

<style>
</style>
